package org.example.juc.p10;

import ch.qos.logback.core.util.TimeUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @author lou ke
 * @since 2024/2/10 17:39
 * <p>
 * web服务器中使用的多，如springboot中采用死循环加.sleep(10000)的方式保证程序一直运行
 */
@Slf4j
public class SleepThread {

    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            try {

                // 完成延迟任务
                // Thread.sleep(1000);
                // boolean interrupted = Thread.interrupted();
                // log.info(interrupted+"");

                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            log.info("睡眠完毕");

            // while (true) {
            //
            // }

        });
        thread.start();
        boolean interrupted = thread.isInterrupted();
        log.info(interrupted+"");

        // 线程中断
        thread.interrupt();
        boolean interrupted1 = thread.isInterrupted();
        log.info(interrupted1+"");
    }

}
